<div class="layui-fluid" lay-title="生成代码">
  <div class="layui-card">
    <div class="layui-card-body" style="padding: 15px;">
      <form class="layui-form" action="" lay-filter="form-code">
        

<script type="text/html" id="tpl_config" template lay-url="code/renderConfig" 
	lay-type="post" 
	lay-done="layui.form.render('select');initArea();">
        
		<div class="layui-form-item">
          <label class="layui-form-label">模板</label>
          <div class="layui-input-block">
			<div class="layui-inline">
            <select name="templ" id="templ">
			  {{# layui.each(d.tpls,function(i,item){ }}
              <option value="{{item}}">{{item}}</option>
              {{# }) }}
             
            </select>
			</div>
          </div>
        </div>

        <div class="layui-form-item layui-form-text">
          <label class="layui-form-label">配置文件</label>
          <div class="layui-input-block">
            <textarea id="config" name="config" placeholder="请输入内容" class="layui-textarea" rows="18">
				{{d.config}}
			</textarea>
          </div>
        </div>
</script>        
        
        <div class="layui-form-item">
          <div class="layui-input-block">
          	<p class="nepadmin-c-red nepadmin-bold">如有修改，请先保存配置文件</p>
            <button class="layui-btn" lay-submit lay-filter="save-code">保存</button>
            <button class="layui-btn" lay-submit lay-filter="generate-code">生成代码</button>
           	
          </div>
        </div>
        
      </form>
    </div>
  </div>
</div>

<script>
function initArea(){
	  editAreaLoader.init({
			id: "config"		
			,start_highlight: true	
			,font_size: "10"
			,font_family: "verdana, monospace"
			,allow_resize: "no"
			,allow_toggle: false
			,word_wrap: true
			,language: "en"
			,syntax: "xml"	
			,toolbar: "new_document, |, search, go_to_line, |, select_font, |, change_smooth_selection, highlight, reset_highlight, |, help"
				
		});
}
  layui.use(['admin', 'form', 'laydate'], function () {
    var $ = layui.$
      , admin = layui.admin
      , element = layui.element
      , layer = layui.layer
      , laydate = layui.laydate
      , form = layui.form;

    form.render(null, 'form-code');

  
    form.on('submit(save-code)', function (data) {
    	 var content = editAreaLoader.getValue("config");
    	 admin.post({
             url:'code/updateConfig',
             data:{
            	 config:content
             },
             success:function(res){
            	 if(res.code=="0"){
            		admin.modal.success("保存成功！") 
             	 }else{
             		admin.modal.error("保存失败！") 
             	 }
             }
         });
         return false;
    });
    /* 生成代码 */
    form.on('submit(generate-code)', function (data) {
    	$(".layui-btn").attr("disabled",true);
    	$(".layui-btn").addClass("layui-disabled");
    	//admin.modal.info("正在生成代码，请稍等！");
    	 admin.get({
    		 timeout:-1,
             url:'code/generateCode',
             data:{
            	 tplname:$("#templ").val()
             },
             success:function(res){
            	 if(res.code=="0"){
            		admin.modal.success("生成代码成功！")
            	 }else{
            		admin.modal.error("生成代码失败！")
            	 }
            	 
             },
             complete:function(){
            	 $(".layui-btn").attr("disabled",false);
            	 $(".layui-btn").removeClass("layui-disabled");
             }
         });
         return false;
    });
   
  });
  
</script>